package controllayer;

import java.sql.SQLException;
import java.util.ArrayList;

import dblayer.*;
import modellayer.Cities;
import modellayer.Customer;

public class CustomerCtr {
	
	private DBCustomer dbC;

	public CustomerCtr() {
		dbC = new DBCustomer();
		
	}
	
	
	
	/**
	 * 
	 * @param customerID
	 * @return
	 */
	public Customer findCostumer(int customerID) throws SQLException
	{
		return dbC.selectSingleCustomer(customerID, true);
	}
	
	/**
	 * 
	 * @return
	 */
	public String[] customerToComboBox()
	{
		ArrayList<Customer> customerList = dbC.getAllCustomers(true);
		int index = 0;
		String data[] = new String[dbC.getAllCustomers(true).size()];
		
		while(index < dbC.getAllCustomers(true).size())
		{
			Customer customer = customerList.get(index);
			
			data[index] = customer.getName();
			index++;
		}
		
		return data;
	}

	public Customer getCustomer(String customerName)
	{
		Customer customer = null;
		int index = 0;
		ArrayList<Customer> customerList = dbC.getAllCustomers(true);
		
		while(index < customerList.size())
		{
			customer = customerList.get(index);
			if(customer.getName().equals(customerName)){
				break;
			}else {
				customer = null;
			}
			index++;
		}
		
		
		return customer;
	}
}
